local Mercenary = class("Mercenary")


local check = function(v,d)
	if v then
		return v
	else
		return d
	end
end

function Mercenary:read(value)
	-- optional string uid = 1;
	-- optional int32  tid = 2;	//type id
	-- optional int32  level = 3;
	-- optional int32  exp = 4;
	-- optional int32  friendlyLv = 5;
	-- optional int32  friendlyExp = 6;
	-- optional int32  sp = 7;			 // 能力值
	-- optional int32  spLv = 8;		 // 成长
	-- optional int32	baSklMax = 9;    // 基础技能槽上限
	-- repeated int32	baSklLibID = 10; // 基础技能库(mercenary_skill表的ID字段
	-- optional int32	btSklMax = 11;   // 战斗技能槽上限
	-- repeated int32	btSklLibID = 12; // 战斗技能库(mercenary_skill表的ID字段)
	-- optional int32	lfSklMax = 13;   // 生活技能槽上限(！！不用了)
	-- repeated int32	lfSklLibID = 14; // 生活技能库(mercenary_skill表的ID字段)(！！不用了)

	self.uid = check(value.uid,self.uid)
	self.tid = check(value.tid,self.tid)
	self.level = check(value.level,self.level)
	self.exp = check(value.exp,self.exp)
	self.friendlyLv = check(value.friendlyLv,self.friendlyLv)--亲密度等级
	self.friendlyExp = check(value.friendlyExp,self.friendlyExp)--亲密度当前经验
	self.sp = check(value.sp,self.sp)--能力值
	self.spLv = check(value.spLv,self.spLv)--成长值

	self.baSklMax = check(value.baSklMax,self.baSklMax)
	if value.baSklLibID then
		self.baSklLibID = clone(value.baSklLibID)
	end
	self.btSklMax = check(value.btSklMax,self.btSklMax)
	if value.btSklLibID then
		self.btSklLibID = clone(value.btSklLibID)
	end
	self.skillID = check(value.skillID,self.skillID)--天赋技能
	-- print("Mercenary:read ---- self.skillID = ",self.skillID)
	-- print("Mercenary:read ---- self.baSklMax = ",self.baSklMax)
	-- dump(self.baSklLibID)
	-- print("Mercenary:read ---- self.btSklMax = ",self.btSklMax)
	-- dump(self.btSklLibID)
	-- self.btSklMax = check(value.btSklMax)--战斗技能槽上限
	-- self.btSklLibID = check(value.btSklLibID)--战斗技能库(mercenary_skill表的Team字段)
	-- print("Mercenary:read ---- 1")
	-- dump(self.btSklLibID)

	-- self.lfSklMax = check(value.lfSklMax)--生活技能槽上限
	-- self.lfSklLibID = check(value.lfSklLibID)--生活技能库(mercenary_skill表的Team字段)
	-- dump(self.lfSklLibID)
end

function Mercenary:write(value)
	value.uid = self.uid
	value.tid = self.tid
	value.level = self.level
	value.exp = self.exp
	value.friendlyLv = self.friendlyLv
	value.friendlyExp = self.friendlyExp
	value.sp = self.sp
	value.spLv = self.spLv
	value.baSklMax = self.baSklMax
	value.baSklLibID = self.baSklLibID
	value.btSklMax = self.btSklMax
	value.btSklLibID = self.btSklLibID
	value.skillID = self.skillID
end



function Mercenary:ctor()
	self.itemBagType = Enums.ItemBagType.mercenary
	
	self.uid = ""
	self.tid= 0
	self.level = 0
	self.exp = 0
	self.friendlyLv = 0
	self.friendlyExp = 0
	self.sp = 0
	self.spLv = 0
	self.baSklMax = 0
	self.baSklLibID = {}
	self.btSklMax = 0
	self.btSklLibID = {}
	self.skillID = 0
end

function Mercenary:toJson()
	return json.encode({uid=self.uid,tid=self.tid,level=self.level,exp=self.exp,friendlyLv=self.friendlyLv,friendlyExp=self.friendlyExp,sp=self.sp,spLv=self.spLv,baSklMax=self.baSklMax,baSklLibID=self.baSklLibID,btSklMax=self.btSklMax,btSklLibID=self.btSklLibID,skillID=self.skillID})
end

return Mercenary